/**
 *
 *
 * @author TOTORO
 * @date 2021/8/29 20:17
 */
// 点击任何一个选择框，触发选项
$(function () {
    // 进入页面，加载一次
    $(document).ready(getNewData())

    $(".options-wrap").click(function () {
        var $super = $(this);
        // 将所有选项框改为关闭状态
        $(".arrow").removeClass("icon-new_shangjiantou").addClass("icon-new_xiajiantou");
        // 判断本次点击的是否打开，如果打开，则收回
        var isOpen = $(this).find(".options-content").hasClass("show");
        if(isOpen){
            $(this).find(".options-content").removeClass("show").addClass("hide");
            return false;
        }
        $(".options-content").removeClass("show").addClass("hide");
        // 打开本次点击的选项框
        $(this).find(".options-content").removeClass("hide").addClass("show");
        // 将本次选项框改为打开状态
        $(this).find(".arrow").removeClass("icon-new_xiajiantou").addClass("icon-new_shangjiantou");

        // 点击选项将值放到本次容器中
        $(".options-item").off("click").on("click",function(){
            var $valueEl = $(this).children(":first-child");
            var value = $valueEl.text();
            var spotId = $(this).attr("data-spot-id");
            $(this).parents(".options-wrap").attr("data-value", spotId);
            $super.find(".show-text").text(value);
            console.log(value);
        });


    });



    //点击其他文档下拉框消失
    $(document).mouseup(function(e) {
        var con = $('.options-wrap');
        e.stopPropagation();
        if (con.has(e.target).length == 0) {
            $(".arrow").removeClass("icon-new_shangjiantou").addClass("icon-new_xiajiantou");
            $(".options-content").removeClass("show").addClass("hide");
            // $(".rc-select-enabled").removeClass("rc-select-open");
        }
    });

    // 点击查询，获取所有条件
    $("#rfSubmit").click(function () {
        getNewData();
    })
});

var getNewData = function () {
    // 先获取所有下拉框的条件
    var terms = {};
    var $selectBoxes = $(".options-wrap");
    $selectBoxes.each(function () {
        terms[$(this).attr("data-key")] = $(this).attr("data-value");
    });
    // 获取所有时间条件
    terms['startTime'] = $("#startTime").val();
    terms['endTime'] = $("#endTime").val();
    var jsonStr = JSON.stringify(terms);
    // 加载
    $(".mod-loading-layer").show();
    setTimeout(function () {
        $(".mod-loading-layer").hide();
    }, 300);

    $.ajaxSettings.async = false;
    $.post("/dispute_logic/findTermBuyerDisputeListData.htm", {"jsonString": jsonStr}, res=>{
        // 清空之前的
        $(".disputelist-listHeader").nextAll().remove();
        var to = eval("("+ res +")");
        var response = to.data;
        // 循环json动态生成数据
        for (let i = 0; i < response.length; i++) {
            var data = response[i];
            // 展示数据
            var orderId = data['marketOdd'];
            var returnId = data['returnOdd'];
            var orderDetailId = data['marketSrId'];
            var shopId = data['marketSrOrder']['product']['shop']['id'];
            var slid = data['marketSrOrder']['product']['shop']['slid'];
            var shopName = data['marketSrOrder']['product']['shop']['shopName'];
            var productImage = data['marketSrOrder']['product']['productImages'][0]['imagePath'];
            var productName = data['marketSrOrder']['product']['productName'];
            var productSkuData = data['marketSrOrder']['product']['productSpecs']['productSpaceData'];
            var skus = eval("("+ productSkuData +")");
            var returnMoney = data['returnMoney'];
            var returnTime = data['createTime'];
            var returnType = data['returnType'] == 0 ?"仅退款":"退货退款";
            var rsNumber = data['returnStatus'];
            var returnStatus = (rsNumber==11||rsNumber==21||rsNumber==25)?"退款成功":(rsNumber==12||rsNumber==22)?"拒绝退款":rsNumber==26?"退款关闭":"退款进行中";

            var $parentContainer = $(".disputelist-bottomContainer");
            console.log($parentContainer.length)

            var $returnTitle = $("<div class='mod-dispute-header disputeHeader disputelist-disputeListGrid'>\n" +
                "                                <ul>\n" +
                "                                    <li class='value-holder' data-index='0'>\n" +
                "                                        <span class='text-span'>订单编号：</span>\n" +
                "                                        <div class='shop-info-text'>\n" +
                "                                            <div class='copy-container'>\n" +
                "                                                <em>"+ orderId +"</em>\n" +
                "                                                <div class='copy-holder'>\n" +
                "                                                    <span class='copy-action-btn' data-index='0'>复制</span>\n" +
                "                                                </div>\n" +
                "                                            </div>\n" +
                "                                        </div>\n" +
                "                                    </li>\n" +
                "                                    <li class='value-holder' data-index='1'>\n" +
                "                                        <span class='text-span'>退款编号：</span>\n" +
                "                                        <div class='shop-info-text'>\n" +
                "                                            <div class='copy-container'>\n" +
                "                                                <em>"+ returnId +"</em>\n" +
                "                                            </div>\n" +
                "                                        </div>\n" +
                "                                    </li>\n" +
                "                                </ul>\n" +
                "                                <em class='mod-dispute-header-shop value-holder'>\n" +
                "                                    <img src='//img.alicdn.com/tps/TB1WVBmLpXXXXcJaXXXXXXXXXXX-36-36.png' alt='"+ shopName +"'>\n" +
                "                                    <div class='shop-info-text shop-holder'>\n" +
                "                                        <div>\n" +
                "                                            <div class='shop-name'>\n" +
                "                                                "+ shopName +"\n" +
                "                                            </div>\n" +
                "                                        </div>\n" +
                "                                    </div>\n" +
                "                                </em>\n" +
                "                                <span class='mod-ww'>\n" +
                "                                    <span class='ww-light ww-large'>\n" +
                "                                        <a class='ww-inline ww-online' data-to-uid='"+ slid +"' title='点此可以直接和卖家交流选好的宝贝，或相互交流网购体验，还支持语音视频噢。'>\n" +
                "                                            <span>旺旺在线</span>\n" +
                "                                        </a>\n" +
                "                                    </span>\n" +
                "                                </span>\n" +
                "                                <div class='dispute-header-child'></div>\n" +
                "                            </div>").appendTo($parentContainer);

            // 详细信息

            var $returnInfo = $("<div class='mod-dispute-body disputeBody disputelist-disputeListGrid'>\n" +
                "                                <div class='mod-dispute-body-col mod-dispute-iteminfo' style='width:37.5%;'>\n" +
                "                                    <img class='item-img hand' src='"+ productImage +"' alt='"+ productName +"' title='"+ productName +"'>\n" +
                "                                    <p class='hand title' title='"+ productName +"'>\n" +
                "                                        "+ productName +"</p>\n" +
                "                                    <div>\n" +
                "                                        <ul class='hand show-sku'>\n" +
                "                                        </ul>\n" +
                "                                    </div>\n" +
                "                                    <div>\n" +
                "                                        <ul class='item-icons'></ul>\n" +
                "                                    </div>\n" +
                "                                </div>\n" +
                "                                <div class='mod-dispute-body-col brand' style='width:12.5%;'>\n" +
                "                                    <p>\n" +
                "                                        <span>￥"+ returnMoney +"</span>\n" +
                "                                    </p>\n" +
                "                                </div>\n" +
                "                                <div class='mod-dispute-body-col' style='width:12.5%;'>\n" +
                "                                    <p>\n" +
                "                                        <span>"+ returnTime +"</span>\n" +
                "                                    </p></div>\n" +
                "                                <div class='mod-dispute-body-col brand' style='width:12.5%;'>\n" +
                "                                    <p>\n" +
                "                                        <span>"+ returnType +"</span>\n" +
                "                                    </p></div>\n" +
                "                                <div class='mod-dispute-body-col warn' style='width:12.5%;'>\n" +
                "                                    <p>\n" +
                "                                        <span>"+ returnStatus +"</span>\n" +
                "                                    </p>\n" +
                "                                </div>\n" +
                "                                <div class='mod-dispute-body-col brand' style='width:10.5%;'>\n" +
                "                                    <a href='/dispute/detail.htm?bizOrderId="+ orderId +"&detailId="+ orderDetailId +"&bizReturnId="+ returnId +"' target='_blank'>\n" +
                "                                        <span>服务详情</span>\n" +
                "                                    </a>\n" +
                "                                </div>\n" +
                "                            </div>").appendTo($parentContainer);

            // 循环本次商品的sku
            for (let skusKey in skus) {
                $returnInfo.find(".show-sku").append("<p>"+ skusKey+":"+skus[skusKey] +"</p>");
            }
        }
    })
}
